﻿package  {
	import flash.display.MovieClip;
	import com.cb.model.WorldModel;
	import flash.display.StageScaleMode;
	import flash.events.Event;
	import flash.display.StageAlign;
	import com.cb.model.objectmodels.Circle2DModel;
	import com.cb.model.objectmodels.Frame2DModel;
	import flash.events.MouseEvent;
	
	public class main extends MovieClip{
		
		public function main() {
			// constructor code
			if(stage){
				init();
			}else{
				this.addEventListener(Event.ADDED_TO_STAGE, init);
			}
		}
		
		private function init(e:Event = null):void
		{
			stage.scaleMode = StageScaleMode.NO_SCALE;
			stage.align = StageAlign.TOP_LEFT;
			
			this.addChild(WorldModel.getInstance().worldView);
			WorldModel.getInstance().updateDimensions(stage.stageWidth, stage.stageHeight);
			
			var frame2DModel:Frame2DModel = new Frame2DModel(stage.stageWidth, stage.stageHeight);
			this.addChild(frame2DModel.frame2DView);
			
			stage.addEventListener(MouseEvent.MOUSE_DOWN, mouseDownHandler);
			stage.addEventListener(Event.ENTER_FRAME, onFrame);
			stage.addEventListener(Event.RESIZE, onScreenResize);
		}
		
		private function onFrame(e:Event):void
		{
			WorldModel.getInstance().update();
		}
		
		private function mouseDownHandler(e:MouseEvent)
		{
			var circle2DModel:Circle2DModel = new Circle2DModel(10 + Math.random() * 25, this.mouseX, this.mouseY);
		}
		
		private function onScreenResize(e:Event):void
		{
			WorldModel.getInstance().updateDimensions(stage.stageWidth, stage.stageHeight);
		}
	}
	
}
